package cn.kgm.makeGodV2.ruleEngine.area.scope;

import cn.kgm.makeGodV2.ruleEngine.area.AreaSite;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * @Version 1.8
 * @Author: Kappi
 * @Date: 2025-10-10 10:06
 * @Description: cn.kgm.makeGodV2.ruleEngine.area.scope.CircleScope
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CircleScope extends AreaScope {

    // 原点坐标
    private AreaSite center;
    // 半径
    private Integer radius;
    // 圆内的方形区域
    private SquareScope squareScope;

    public CircleScope(AreaSite center, Integer radius) {
        this.center = center;
        this.radius = radius;
        this.squareScope = SquareScope.builder()
                .topLeft(new AreaSite(center.getX() - radius, center.getY() - radius))
                .bottomRight(new AreaSite(center.getX() + radius, center.getY() + radius))
                .build();
    }

    @Override
    public boolean contains(AreaSite site) {
        return squareScope.contains(site) && containsInCircle(site);
    }

    private boolean containsInCircle(AreaSite site) {
        return (site.getX() - center.getX()) * (site.getX() - center.getX()) + (site.getY() - center.getY()) * (site.getY() - center.getY()) <= radius * radius;
    }
}
